package p270jp.pxv.android.view;

import android.content.Context;
import android.util.AttributeSet;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.Objects;
import p013ad.Action;
import p013ad.Consumer;
import p014ae.C0135p4;
import p014ae.C0146r;
import p014ae.C0147r4;
import p014ae.C0185y;
import p071cd.Functions;
import p187gl.PixivRequest;
import p270jp.pxv.android.model.ContentRecyclerViewState;
import p270jp.pxv.android.model.ResponseAttacher;
import p270jp.pxv.android.response.PixivResponse;
import p374nm.C5393g;
import p374nm.C5395h;
import p416pb.ConstructorConstructor;
import p517td.BehaviorSubject;
import p547uh.C6513q0;
import p547uh.C6578v3;
import p593wc.AbstractC6902j;
import p607x0.C7050l;
import p645yc.AndroidSchedulers;
import p671zc.CompositeDisposable;

/* renamed from: jp.pxv.android.view.ContentRecyclerView */
/* loaded from: classes2.dex */
public class ContentRecyclerView extends RecyclerView {

    /* renamed from: P0 */
    public static final /* synthetic */ int f19468P0;

    /* renamed from: J0 */
    public C7050l f19470J0;

    /* renamed from: K0 */
    public ResponseAttacher f19471K0;

    /* renamed from: M0 */
    public RecyclerView.AbstractC0807p f19473M0;

    /* renamed from: N0 */
    public String f19474N0;

    /* renamed from: O0 */
    public boolean f19475O0;

    /* renamed from: I0 */
    public final CompositeDisposable f19469I0 = new CompositeDisposable();

    /* renamed from: L0 */
    public BehaviorSubject<ContentRecyclerViewState> f19472L0 = new BehaviorSubject<>();

    /* renamed from: jp.pxv.android.view.ContentRecyclerView$a */
    /* loaded from: classes2.dex */
    public class C4368a extends RecyclerView.AbstractC0807p {
        public C4368a() {
            ContentRecyclerView.this = r1;
        }

        @Override // androidx.recyclerview.widget.RecyclerView.AbstractC0807p
        /* renamed from: b */
        public void mo1494b(RecyclerView recyclerView, int i, int i2) {
            int childCount = recyclerView.getChildCount();
            int T = recyclerView.getLayoutManager().m10807T();
            int g1 = ((LinearLayoutManager) recyclerView.getLayoutManager()).m10935g1();
            ContentRecyclerView contentRecyclerView = ContentRecyclerView.this;
            if (!contentRecyclerView.f19475O0 && T - childCount < g1 + 10) {
                contentRecyclerView.m4507x0();
            }
        }
    }

    public ContentRecyclerView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
    }

    /* renamed from: A0 */
    public void m4511A0() {
        m4510B0();
        C4368a aVar = new C4368a();
        this.f19473M0 = aVar;
        m10869h(aVar);
    }

    /* renamed from: B0 */
    public void m4510B0() {
        RecyclerView.AbstractC0807p pVar = this.f19473M0;
        if (pVar != null) {
            m10870g0(pVar);
            this.f19473M0 = null;
        }
    }

    public String getNextUrl() {
        return this.f19474N0;
    }

    public boolean getRequesting() {
        return this.f19475O0;
    }

    public BehaviorSubject<ContentRecyclerViewState> getState() {
        return this.f19472L0;
    }

    @Override // androidx.recyclerview.widget.RecyclerView, android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        m4509v0();
    }

    public void setNextUrl(String str) {
        this.f19474N0 = str;
    }

    /* renamed from: v0 */
    public void m4509v0() {
        this.f19469I0.m80f();
        m4510B0();
    }

    /* renamed from: w0 */
    public boolean m4508w0() {
        return this.f19474N0 != null;
    }

    /* renamed from: x0 */
    public void m4507x0() {
        if (!this.f19475O0 && this.f19474N0 != null) {
            m4509v0();
            this.f19472L0.mo305g(ContentRecyclerViewState.START_LOAD);
            if (!ConstructorConstructor.m3047b(getContext())) {
                this.f19472L0.mo305g(ContentRecyclerViewState.NETWORK_NOT_CONNECTED_WHEN_LOADING_NEXT);
                this.f19472L0.mo305g(ContentRecyclerViewState.FINISH_LOAD);
                return;
            }
            CompositeDisposable aVar = this.f19469I0;
            C7050l lVar = this.f19470J0;
            String str = this.f19474N0;
            Objects.requireNonNull(lVar);
            AbstractC6902j<PixivResponse> j = PixivRequest.m5813d(str).m986o(AndroidSchedulers.m334a()).m992i(new C0185y(this, 21)).m991j(new C6513q0(this, 1));
            C5393g gVar = new C5393g(this, 1);
            Consumer<? super PixivResponse> eVar = Functions.f5387d;
            Action aVar2 = Functions.f5386c;
            aVar.mo82c(j.m993h(eVar, eVar, gVar, aVar2).m984q(new C0147r4(this, 20), new C5395h(this, 1), aVar2, eVar));
        }
    }

    /* renamed from: y0 */
    public void m4506y0() {
        m4509v0();
        this.f19472L0.mo305g(ContentRecyclerViewState.START_RELOAD);
        if (!ConstructorConstructor.m3047b(getContext())) {
            this.f19472L0.mo305g(ContentRecyclerViewState.NETWORK_NOT_CONNECTED_WHEN_RELOADING);
            this.f19472L0.mo305g(ContentRecyclerViewState.FINISH_RELOAD);
            return;
        }
        this.f19471K0.getResetItemsCallback().resetItems();
        this.f19469I0.m80f();
        CompositeDisposable aVar = this.f19469I0;
        AbstractC6902j j = ((AbstractC6902j) this.f19470J0.f29729a).m986o(AndroidSchedulers.m334a()).m992i(new C0135p4(this, 20)).m991j(new C5393g(this, 0));
        C6578v3 v3Var = new C6578v3(this, 2);
        Consumer<? super Throwable> eVar = Functions.f5387d;
        Action aVar2 = Functions.f5386c;
        aVar.mo82c(j.m993h(eVar, eVar, v3Var, aVar2).m984q(new C5395h(this, 0), new C0146r(this, 20), aVar2, eVar));
    }

    /* renamed from: z0 */
    public void m4505z0(C7050l lVar, ResponseAttacher responseAttacher) {
        this.f19470J0 = lVar;
        this.f19471K0 = responseAttacher;
        m4509v0();
    }
}
